import { defineStore } from "pinia";
import axios from "axios";
import dayjs from "dayjs";

const useStore = defineStore({
  id: "aman",
  state: () => ({
    schemes: {
      time: "",
      ZUUU: null,
      ZUTF: null,
      ZUTFSingle: null,
    },
    inputs: {
      ZUTF: {
        direction: "N",
        usages: {
          westRunway: ["A", "D"],
          eastRunway: ["A"],
          northRunway: ["D"],
        },
        departure: 0,
        timeSpan: 40,
      },
      ZUUU: {
        direction: "N",
        usages: {
          westRunway: ["D"],
          eastRunway: ["A"],
        },
        departure: 0,
        timeSpan: 40,
      },
    },
  }),
  getters: {},
  actions: {
    loadParams() {
      // console.log(
      //   "Going to load AMAN params at:",
      //   dayjs().format("YYYY-MM-DD HH:mm:ss")
      // );
      axios
        .get("api/planner_params_get.php")
        .then((response) => {
          // console.log("AMAN params loaded at:", response.data.time);
          this.schemes.time = response.data.time;
          this.schemes.ZUUU = response.data.AMAN.ZUUU;
          this.schemes.ZUTF = response.data.AMAN.ZUTF;
          this.schemes.ZUTFSingle = response.data.AMAN.ZUTFSingle;
          // console.log("AMAN params is setted:", this.schemes);
        })
        .catch((error) => {
          console.error("An error occured while loading AMAN params:", error);
        });
    },
  },
});

export default useStore;
